package com.woniu.outlet.dao;

import com.woniu.outlet.po.OrderDetailsPo;
import com.woniu.outlet.po.OrderDetailsPoExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

@Repository
public interface OrderDetailsPoMapper {
    long countByExample(OrderDetailsPoExample example);

    int deleteByExample(OrderDetailsPoExample example);

    int deleteByPrimaryKey(Long id);

    int insert(OrderDetailsPo record);

    int insertSelective(OrderDetailsPo record);

    List<OrderDetailsPo> selectByExample(OrderDetailsPoExample example);

    OrderDetailsPo selectByPrimaryKey(Long id);

    int updateByExampleSelective(@Param("record") OrderDetailsPo record, @Param("example") OrderDetailsPoExample example);

    int updateByExample(@Param("record") OrderDetailsPo record, @Param("example") OrderDetailsPoExample example);

    int updateByPrimaryKeySelective(OrderDetailsPo record);

    int updateByPrimaryKey(OrderDetailsPo record);

    @Select("select od.spare1 spare1 from erp_order_equipment.ERP_order_details od\n" +
            "\t\t\t\t\t\tleft join erp_order_equipment.ERP_order o on o.order_no=od.order_no\n" +
            "\t\t\t\t\t\tleft join erp_wavehouse.ERP_project pj on pj.id=od.product_id\n" +
            "\t\t\t\t\t\tleft join ERP_pro_plan pp on pp.order_id=o.id\n" +
            "\t\t\t\t\t\twhere pp.id=#{proPlanId} and pj.spare1=#{proName}")
    String getStatus(@Param("proPlanId") Long proPlanId,@Param("proName") String proName);

    @Select("select od.order_no orderNo,wp.project_cocde projectCocde,wp.spare1 proName,wp.specification_unit specificationUnit,od.num from erp_order_equipment.ERP_order_details od\n" +
            "\t\t\t\t\t\tleft join erp_order_equipment.ERP_order o on o.order_no=od.order_no\n" +
            "            left join erp_wavehouse.ERP_project wp on wp.id=od.product_id\n" +
            "            where o.id=#{orderId}")
    List<OrderDetailsPo> findAllProListByOrderId(Long orderId);

    @Select("select od.id id from erp_order_equipment.ERP_order_details od\n" +
            "\t\t\t\t\t\tleft join erp_order_equipment.ERP_order o on o.order_no=od.order_no\n" +
            "\t\t\t\t\t\tleft join erp_wavehouse.ERP_project pj on pj.id=od.product_id\n" +
            "\t\t\t\t\t\tleft join ERP_pro_plan pp on pp.order_id=o.id\n" +
            "\t\t\t\t\t\twhere pp.id=#{proPlanId} and pj.spare1=#{proName}")
    Integer getId(@Param("proPlanId") Long proPlanId,@Param("proName") String proName);

    @Update("update erp_order_equipment.ERP_order_details od set od.spare1=#{sta} where od.id=#{odId}")
    void update(@Param("odId") Integer odId,@Param("sta") String sta);
}